<style type="text/css">
.modal#set_member_discount{
	border-radius: 0;
	width: 500px;
}
.modal#set_member_discount .modal-body{
	text-align: center;
}
.modal#set_member_discount .modal-body dl{
	margin-top: 0;
	margin-bottom: 10px;
	width: 100%;
	overflow: hidden;
}
.modal#set_member_discount .modal-body dl:last-child{
	margin-bottom: 0;
}
.modal#set_member_discount .modal-body dl dt,.modal#set_member_discount .modal-body dl dd{
	display: inline-block;
	line-height: 30px;
}
.modal#set_member_discount .modal-body dl dt{
	width: 35%;
	text-align: right;
	font-weight: normal;
	float: left;
}
.modal#set_member_discount .modal-body dl dd{
	text-align: left;
	margin-left: 0;
	width: 63%;
	float: right;
}
</style>
<div class="modal fade hide" id="set_member_discount" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>设置商品折扣</h3>
			</div>
			<div class="modal-body" id="member_discount">
				{foreach name="$level_list" item="vo"}
					<dl>
						<dt>{$vo.level_name}</dt>
						<dd>
							<input class="input-common harf" data-level-id="{$vo.level_id}" maxlength="2"><em class="unit">%</em>
						</dd>
					</dl>
				{/foreach}
			</div>
			<div class="modal-footer">
				<button class="btn-common btn-big" onclick="save_goods_discount();">保存</button>
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	var is_sub = false;
	function save_goods_discount(){
		var member_discount_arr = new Array();
		$("#member_discount dl dd input").each(function(){
			var discount = parseInt($(this).val());
			if(discount != NaN && discount > 0 && discount <= 100){
				var member_discount = new Object();
					member_discount.level_id = $(this).attr("data-level-id");
					member_discount.discount = discount;
				member_discount_arr.push(member_discount);
			}
		})

		var goods_ids= new Array();
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				goods_ids.push($(this).val());
			}
		});
		if(member_discount_arr.length > 0 && goods_ids.length > 0){
			if(is_sub) return;
			is_sub = true;
			$.ajax({
				type : "post",
				url : "{:__URL('ADMIN_MAIN/goods/setMemberDiscount')}",
				data : {
					member_discount_arr : JSON.stringify(member_discount_arr),
					goods_ids : goods_ids.toString()
				},
				success : function(data){
					$("#set_member_discount").modal("hide");
					if(data["code"] > 0){
						showMessage("success",data["message"],location.href);
					}else{
						is_click = false;
						showMessage("error",data["message"]);
					}
				}
			})
		}else{
			$("#set_member_discount").modal("hide");
		}
	}
</script>
